package com.jf3q.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jf3q.admin.service.EduBannerService;
import com.jf3q.common.domain.EduBanner;
import com.jf3q.common.vo.ResultVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Date;

@RestController
@Tag(name = "轮播图")
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    EduBannerService eduBannerService;

    @PostMapping("/getList/{pageNum}")
    @Operation(summary = "查询轮播图列表")
    public ResultVo getList(@PathVariable Integer pageNum, @RequestBody EduBanner eduBanner){
        Page<EduBanner> page= eduBannerService.getPage(pageNum,eduBanner);
        return ResultVo.success("查询所有轮播图",page);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除图片")
    public ResultVo del(@PathVariable String id){
        Boolean del = eduBannerService.del(id);
        if (del){
            return ResultVo.success("删除成功",null);
        }
        return ResultVo.error("删除失败");
    }

    @PostMapping("/saveOrUpdate")
    @Operation(summary = "添加轮播图")
    public ResultVo add(@RequestBody EduBanner eduBanner){
        eduBanner.setEduCreate(new Date());
        boolean save = eduBannerService.saveOrUpdate(eduBanner);
        if (save){
            return ResultVo.success("成功",null);
        }
        return ResultVo.error("失败");
    }


}
